from .base_model import BaseModel
from django.contrib.auth.models import Permission
from django.db import models

class Role(BaseModel):
    """系统角色定义"""
    PRINCIPAL = 'principal'       # 校长
    GRADE_LEADER = 'grade_leader' # 年级组长
    HOMEROOM_TEACHER = 'homeroom_teacher' # 班主任
    TEACHER = 'teacher'         # 教师
    ASSISTANT = 'assistant'     # 班级小助手

    ROLE_CHOICES = [
        (PRINCIPAL, '校长'),
        (GRADE_LEADER, '年级组长'),
        (HOMEROOM_TEACHER, '班主任'),
        (TEACHER, '教师'),
        (ASSISTANT, '班级小助手'),
    ]

    name = models.CharField(max_length=50, choices=ROLE_CHOICES, unique=True, verbose_name="角色标识", db_column="role_code")  # 数据库列别名role_code
    display_name = models.CharField(max_length=50, verbose_name="角色显示名称", db_column="role_name")  # 新增显示名称字段（别名）
    description = models.TextField(blank=True, verbose_name="角色详细说明", db_column="role_desc")  # 数据库列别名role_desc
    permissions = models.ManyToManyField(Permission, blank=True, verbose_name="角色拥有权限", db_column="role_perms")  # 数据库列别名role_perms
    class Meta:
        verbose_name = "角色"
        verbose_name_plural = "角色"
    def __str__(self):
        return self.get_name_display()